﻿#ifndef STATISTICSWORKER_H
#define STATISTICSWORKER_H

#include <QObject>
#include <IDatabase.h>
#include <QDate>
#include <QMap>
#include <SqliteDatabase.h>
#include <QDate>
#include <QJsonDocument>
#include <SqliteDatabase.h>
#include <StatisticsEntity.h>
class StatisticsWorker : public QObject
{
    Q_OBJECT
public:
    explicit StatisticsWorker(QString databaseType = "QSQLITE", QString databaseName = "database.db", QObject *parent = nullptr);
    ~StatisticsWorker();
signals:
public slots:
    void onInit();
    virtual void flashStatistics();
    void clearTodayStatistics();
    void onDateFromChanged(const QDate& from);
    void onDateToChanged(const QDate& to);
    void clearDateStatistics(QDate date);
    void onDateFromChangedByID(const QDate& from, const QString& findName);
    void onDateChanged(const QDate& from, const QDate& to);

protected:
    QJsonObject getData();
    //数据统计表按给定的key和date查询
    QVariant  getData(QString key,QString date=QDate::currentDate().toString("yyyy-MM-dd"));
    void setData(const QJsonObject& data);
    //数据统计表按给定的key和date修改
    void setData(QVariant  data,QString key,QString date=QDate::currentDate().toString("yyyy-MM-dd"));
    virtual void initData(){};
signals:
    void sigStatisticsUpdated(const QJsonObject& data);
    void sigStatisticsTableUpdated(const QJsonObject& data);

protected:
    QMap<QString,QString> mapEngChn;
    IDatabase* database;
    QDate m_dateFrom;
    QDate m_dateTo;
    QString m_tableName;
    bool m_showAll;
    bool m_isAllType;
    QString m_databaseType;
    QString m_databaseName;
};

#endif // STATISTICSWORKER_H
